package api

import (
	"file_sys_server/model"
	"file_sys_server/service"
	"net/http"

	"github.com/gin-gonic/gin"
)

var mfdcg_samples = []model.Sample_bean_mfdcg{}

/*
	获取MFDCG数据
*/
func GetSampleBean_MFDCG(ctx *gin.Context) {

	// TODO 获取本地数据库存在的数据
	//
	// Sample_bean_mfdcg
	ctx.IndentedJSON(http.StatusOK, mfdcg_samples)
}

func AddSampleBean_MFDCG(ctx *gin.Context) {
	var newItem model.Sample_bean_mfdcg // 新建记录
	response := &Response{0, ""}

	//bind new Record
	if err := ctx.BindJSON(&newItem); err != nil { // 获取

		return
	}

	if len(newItem.Limit) == 0 {
		response.Code = 10001
		response.Msg = "字段缺失"
		ctx.IndentedJSON(http.StatusOK, response)
		return
	}

	mfdcg_samples = append(mfdcg_samples, newItem)
	response.Code = 0
	response.Msg = "success"
	ctx.IndentedJSON(http.StatusCreated, response)

}

//添加本地样品到数据库
func AddSampleBean_FromLocal_MFDCG(c *gin.Context) {
	response := service.AddRecordsFromLocal()
	c.IndentedJSON(http.StatusOK, response)
}

// 获取数据库中存储所有样品信息
func GetSampleList_MFDCG(c *gin.Context) {
	response := service.GetSampleList()
	c.IndentedJSON(http.StatusOK, response)
}
